<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css" integrity="sha256-mUZM63G8m73Mcidfrv5E+Y61y7a12O5mW4ezU3bxqW4=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"tallgy.gitee.io","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="只是一个知识的搬运工">
<meta property="og:type" content="website">
<meta property="og:title" content="tallgy&#39;s blog">
<meta property="og:url" content="http://tallgy.gitee.io/page/2/index.html">
<meta property="og:site_name" content="tallgy&#39;s blog">
<meta property="og:description" content="只是一个知识的搬运工">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="tallgy">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://tallgy.gitee.io/page/2/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":true,"isPost":false,"lang":"zh-CN","comments":"","permalink":"","path":"page/2/index.html","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>tallgy's blog</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">tallgy's blog</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">tallgy</p>
  <div class="site-description" itemprop="description">只是一个知识的搬运工</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">107</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">32</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">74</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/31/%E7%AE%97%E6%B3%95/%E4%B8%AD%E7%AD%89/3-%E6%97%A0%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E6%9C%80%E9%95%BF%E5%AD%90%E4%B8%B2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/31/%E7%AE%97%E6%B3%95/%E4%B8%AD%E7%AD%89/3-%E6%97%A0%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E6%9C%80%E9%95%BF%E5%AD%90%E4%B8%B2/" class="post-title-link" itemprop="url">3-无重复字符的最长子串</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-31 12:48:52" itemprop="dateCreated datePublished" datetime="2022-03-31T12:48:52+08:00">2022-03-31</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AE%97%E6%B3%95/%E4%B8%AD%E7%AD%89/" itemprop="url" rel="index"><span itemprop="name">中等</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="3-无重复字符的最长子串"><a href="#3-无重复字符的最长子串" class="headerlink" title="3-无重复字符的最长子串"></a>3-无重复字符的最长子串</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/</span><br></pre></td></tr></table></figure>

<p>给定一个字符串 s ，请你找出其中不含有重复字符的 最长子串 的长度。</p>
<p>示例 1:</p>
<p>输入: s = “abcabcbb”<br>输出: 3<br>解释: 因为无重复字符的最长子串是 “abc”，所以其长度为 3。<br>示例 2:</p>
<p>输入: s = “bbbbb”<br>输出: 1<br>解释: 因为无重复字符的最长子串是 “b”，所以其长度为 1。<br>示例 3:</p>
<p>输入: s = “pwwkew”<br>输出: 3<br>解释: 因为无重复字符的最长子串是 “wke”，所以其长度为 3。<br>     请注意，你的答案必须是 子串 的长度，”pwke” 是一个子序列，不是子串。</p>
<h2 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h2><p>​        </p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/24/%E9%9A%8F%E7%AC%94/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F-%E6%A1%88%E4%BE%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/24/%E9%9A%8F%E7%AC%94/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F-%E6%A1%88%E4%BE%8B/" class="post-title-link" itemprop="url">正则表达式-案例</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-24 15:01:29" itemprop="dateCreated datePublished" datetime="2022-03-24T15:01:29+08:00">2022-03-24</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-28 18:58:52" itemprop="dateModified" datetime="2023-06-28T18:58:52+08:00">2023-06-28</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">正则表达式</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="几个正则表达式的案例"><a href="#几个正则表达式的案例" class="headerlink" title="几个正则表达式的案例"></a>几个正则表达式的案例</h1><h2 id="数字价格的千分位分割"><a href="#数字价格的千分位分割" class="headerlink" title="数字价格的千分位分割"></a>数字价格的千分位分割</h2><p>​        1234 ==&gt; 1，234</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"></span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/24/%E7%AE%97%E6%B3%95/%E4%B8%AD%E7%AD%89/2-%E4%B8%A4%E6%95%B0%E7%9B%B8%E5%8A%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/24/%E7%AE%97%E6%B3%95/%E4%B8%AD%E7%AD%89/2-%E4%B8%A4%E6%95%B0%E7%9B%B8%E5%8A%A0/" class="post-title-link" itemprop="url">2-两数相加</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-24 10:00:22" itemprop="dateCreated datePublished" datetime="2022-03-24T10:00:22+08:00">2022-03-24</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AE%97%E6%B3%95/%E4%B8%AD%E7%AD%89/" itemprop="url" rel="index"><span itemprop="name">中等</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="两数相加"><a href="#两数相加" class="headerlink" title="两数相加"></a>两数相加</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://leetcode-cn.com/problems/add-two-numbers/</span><br></pre></td></tr></table></figure>



<h2 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h2><p>​        给你两个 非空 的链表，表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的，并且每个节点只能存储 一位 数字。</p>
<p>​        请你将两个数相加，并以相同形式返回一个表示和的链表。</p>
<p>​        你可以假设除了数字 0 之外，这两个数都不会以 0 开头。</p>
<h2 id="题解思路"><a href="#题解思路" class="headerlink" title="题解思路"></a>题解思路</h2><p>​        简单的来说，我们可以两个链表依次相加，循环最长的链表的次数。短的链表对于不存在的值，我们可以设置一个0.这样相加没有什么影响。</p>
<h3 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h3><p>​        这个是每次都是创建一个新的节点。但是我们也可以原地修改原来的节点进行修改。</p>
<p>​        如果要修改原来的节点，那么我们得先找到是谁的系欸但更长，然后再修改长的节点内容。</p>
<p>​        当然，我们也可以不用修改长节点的内容，但是这样的话，我们每次都得判断我们要修改的节点是否没有下一个节点，然后创建下一个节点。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">var addTwoNumbers = function(l1, l2) &#123;</span><br><span class="line">  // 进位判断</span><br><span class="line">  let carry = 0;</span><br><span class="line">  // 创建一个初始节点</span><br><span class="line">  const res = new ListNode(-1);</span><br><span class="line">  // 循环节点，每次都会创建新节点存在cur.next；</span><br><span class="line">  let cur = res;</span><br><span class="line"></span><br><span class="line">  // 循环，循环比较长的节点的次数</span><br><span class="line">  while (l1 || l2) &#123;</span><br><span class="line">    // 取出value，如果这个节点为null，那么值为0.</span><br><span class="line">    // 0相加没有影响。</span><br><span class="line">    const v1 = l1 ? l1.val : 0;</span><br><span class="line">    const v2 = l2 ? l2.val : 0;</span><br><span class="line">    // 两数相加，进位+两个节点的值。</span><br><span class="line">    const sumV = carry + v1 + v2</span><br><span class="line">    // 取余。</span><br><span class="line">    const value = sumV % 10;</span><br><span class="line">    // 判断是否存在进位，我们也可以判断是否大于十。</span><br><span class="line">    carry = parseInt(sumV / 10);</span><br><span class="line"></span><br><span class="line">    // 创建一个新的node，值为value，</span><br><span class="line">    // 然后将这个node，放在next里面</span><br><span class="line">    const node = new ListNode(value);</span><br><span class="line">    cur.next = node;</span><br><span class="line">    // 把cur，给下一个。</span><br><span class="line">    cur = cur.next;</span><br><span class="line">    // 如果节点不为空，那么给下一个。</span><br><span class="line">    l1 &amp;&amp; (l1 = l1.next);</span><br><span class="line">    l2 &amp;&amp; (l2 = l2.next);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  // 判断最后依次是否存在进位。</span><br><span class="line">  if (carry) cur.next = new ListNode(carry);</span><br><span class="line"></span><br><span class="line">  return res.next;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/21/%E7%AE%97%E6%B3%95/%E7%AE%80%E5%8D%95/1-%E4%B8%A4%E6%95%B0%E4%B9%8B%E5%92%8C/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/21/%E7%AE%97%E6%B3%95/%E7%AE%80%E5%8D%95/1-%E4%B8%A4%E6%95%B0%E4%B9%8B%E5%92%8C/" class="post-title-link" itemprop="url">1-两数之和</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-21 11:06:04" itemprop="dateCreated datePublished" datetime="2022-03-21T11:06:04+08:00">2022-03-21</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AE%97%E6%B3%95/%E7%AE%80%E5%8D%95/" itemprop="url" rel="index"><span itemprop="name">简单</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="1-两数之和"><a href="#1-两数之和" class="headerlink" title="1-两数之和"></a>1-两数之和</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://leetcode-cn.com/problems/two-sum/</span><br></pre></td></tr></table></figure>

<h2 id="描述"><a href="#描述" class="headerlink" title="描述"></a>描述</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">给定一个整数数组 nums 和一个整数目标值 target，请你在该数组中找出 和为目标值 target  的那 两个 整数，并返回它们的数组下标。</span><br><span class="line">你可以假设每种输入只会对应一个答案。但是，数组中同一个元素在答案里不能重复出现。</span><br><span class="line">你可以按任意顺序返回答案。</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">示例 1：</span><br><span class="line"></span><br><span class="line">输入：nums = [2,7,11,15], target = 9</span><br><span class="line">输出：[0,1]</span><br><span class="line">解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1] 。</span><br></pre></td></tr></table></figure>



<h2 id="思路："><a href="#思路：" class="headerlink" title="思路："></a>思路：</h2><h3 id="暴力"><a href="#暴力" class="headerlink" title="暴力"></a>暴力</h3><p>​        简单的，那肯定是使用暴力的方法进行解决。使用两次for循环，然后进行判断是否可以满足条件。然后再进行输出。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @param &#123;number[]&#125; nums</span><br><span class="line"> * @param &#123;number&#125; target</span><br><span class="line"> * @return &#123;number[]&#125;</span><br><span class="line"> */</span><br><span class="line">var twoSum = function(nums, target) &#123;</span><br><span class="line">  // 这个就是两次暴力进行一个全部结果的轮询，查看是否有满足条件的情况进行返回</span><br><span class="line">  </span><br><span class="line">  // 第一个 for 循环，从0到n</span><br><span class="line">  for (let i = 0; i &lt; nums.length; i++) &#123;</span><br><span class="line">    // 第二个 for 循环，从i+1 到 n</span><br><span class="line">    for (let j = i+1; j &lt; nums.length; j++) &#123;</span><br><span class="line">      // 如果 下标 i，j 对应的值之和等于 target，那么便返回 i，j</span><br><span class="line">      if (target == (nums[i]+nums[j])) &#123;</span><br><span class="line">        return [i, j]</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  // 没有答案，返回 []</span><br><span class="line">  return []</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>



<h3 id="使用对象的形式"><a href="#使用对象的形式" class="headerlink" title="使用对象的形式"></a>使用对象的形式</h3><p>​    思路：</p>
<p>​        我们只需要记录前面的内容，就可以减少for循环的次数，所以我们将 target-nums[i] 作为key，i作为 value。进行存储，当然我们也可以使用 nums[i] 作为key。性质是相似的。主要的目的就是把数组存下来，然后查找的时候可以不需要循环，而是使用对象快速查找。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @param &#123;number[]&#125; nums</span><br><span class="line"> * @param &#123;number&#125; target</span><br><span class="line"> * @return &#123;number[]&#125;</span><br><span class="line"> */</span><br><span class="line">var twoSum = function(nums, target) &#123;</span><br><span class="line">  // 使用对象来进行存储，key为target减去nums。然后每次通过查询当前nums[i]</span><br><span class="line">  // 是否存在于obj里面来确定是否有。</span><br><span class="line">  const obj = &#123;&#125;;</span><br><span class="line"></span><br><span class="line">  for (let i = 0; i &lt; nums.length; i++) &#123;</span><br><span class="line">    // 取出值。</span><br><span class="line">    const curValue = nums[i]</span><br><span class="line">    // 如果这个值不存在，说明前面没有一个j，使得target-j = i</span><br><span class="line">    // 所以需要将其 target-i 作为key赋值给 obj。</span><br><span class="line">    // 如果存在，那么直接return，对应的下标</span><br><span class="line">    if (obj[curValue] != undefined) return [obj[curValue], i]</span><br><span class="line">    obj[target-curValue] = i;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  return []</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="使用-Map"><a href="#使用-Map" class="headerlink" title="使用 Map"></a>使用 Map</h3><p>​        大致是和使用对象是一样的。区别就是一个是使用的map，一个是使用的对象来进行的存储。思路是一样的。所以我这里就不做写法。</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/15/JavaScript/JavaScript%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/15/JavaScript/JavaScript%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2/" class="post-title-link" itemprop="url">JavaScript类型转换</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-15 10:01:43" itemprop="dateCreated datePublished" datetime="2022-03-15T10:01:43+08:00">2022-03-15</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/%E9%9A%8F%E7%AC%94/" itemprop="url" rel="index"><span itemprop="name">随笔</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="JavaScript类型转换"><a href="#JavaScript类型转换" class="headerlink" title="JavaScript类型转换"></a>JavaScript类型转换</h1><p>​        本文参考文章</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Equality_comparisons_and_sameness</span><br></pre></td></tr></table></figure>



<h2 id="非严格相等判断中的隐式类型转换"><a href="#非严格相等判断中的隐式类型转换" class="headerlink" title="非严格相等判断中的隐式类型转换"></a>非严格相等判断中的隐式类型转换</h2><p>​        因为JavaScript的非严格相等，所以存在在比较时进行类型转换。</p>
<p>转换规则：</p>
<ul>
<li><p>null 和 undefined 互为相等。和基本数据类型为false，引用数据类型通过 isFalsy 来进行判断（Falsy代表的是在Boolean属性中被认为是false的值）</p>
</li>
<li><p>其他类型和number的比较，和基本数据类型会转为数字，引用类型则通过ToPrimitive转换为基本类型然后再进行比较。</p>
<ul>
<li><p>```<br><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive">https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive</a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">* ```</span><br><span class="line">  具体的我们后续再继续了解。</span><br><span class="line">  </span><br><span class="line">  let a = &#123;</span><br><span class="line">    value: 1,</span><br><span class="line">    [Symbol.toPrimitive](hint) &#123;</span><br><span class="line">      console.log(&#x27;hint&#x27;, hint)</span><br><span class="line">  </span><br><span class="line">      if (hint == &#x27;number&#x27;) return this.value</span><br><span class="line">      if (hint == &#x27;string&#x27;) return &#x27;2&#x27;</span><br><span class="line">      return true</span><br><span class="line">    &#125;,</span><br><span class="line">  &#125;</span><br><span class="line">  let b = 12</span><br><span class="line">  </span><br><span class="line">  console.log(a == b)</span><br></pre></td></tr></table></figure></li>
<li><p>我们现在就先知道这个 toPrimitive 的一个作用是什么就好。他会将对象转为一个基本的数据类型。对于一个对象，会先通过 toPrimitive 调用 valueOf 方法转换为 基本数据类型，如果不能，那么便通过toString 转换为基本数据类型，否则便会报错。但是对于date 类型就会反过来进行调用。（有人说是因为date的数值转化较大，所以没有意义转化为数值）</p>
</li>
</ul>
</li>
<li><p>布尔类型的比较，其他类型都转化为number，对象使用ToPrimitive，同时布尔转化为number</p>
</li>
</ul>
<p>所以大致一个转化的思路就是</p>
<p>undefined 和 null 将为 空。</p>
<p>引用类型和其他类型会通过primitive转化为基本类型</p>
<p>其他的有number，以number为主。</p>
<p>布尔和string要转化为number</p>
<p>有一个图也进行了说明：</p>
<img src="/.io//image-20220315133546860.png" alt="image-20220315133546860" style="zoom:67%;">



<table>
<thead>
<tr>
<th></th>
<th></th>
<th>B</th>
<th>被</th>
<th>比</th>
<th>较</th>
<th>值</th>
<th>B</th>
</tr>
</thead>
<tbody><tr>
<td>A</td>
<td></td>
<td>Undefined</td>
<td>Null</td>
<td>Number</td>
<td>String</td>
<td>Boolean</td>
<td>Object</td>
</tr>
<tr>
<td>被</td>
<td>Undefined</td>
<td><code>true</code></td>
<td><code>true</code></td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>IsFalsy(B)</code></td>
</tr>
<tr>
<td>比</td>
<td>Null</td>
<td><code>true</code></td>
<td><code>true</code></td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>IsFalsy(B)</code></td>
</tr>
<tr>
<td>较</td>
<td>Number</td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>A === B</code></td>
<td><code>A === ToNumber(B)</code></td>
<td><code>A=== ToNumber(B)</code></td>
<td><code>A== ToPrimitive(B)</code></td>
</tr>
<tr>
<td>值</td>
<td>String</td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>ToNumber(A) === B</code></td>
<td><code>A === B</code></td>
<td><code>ToNumber(A) === ToNumber(B)</code></td>
<td><code>ToPrimitive(B) == A</code></td>
</tr>
<tr>
<td>A</td>
<td>Boolean</td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>ToNumber(A) === B</code></td>
<td><code>ToNumber(A) === ToNumber(B)</code></td>
<td><code>A === B</code></td>
<td><code>ToNumber(A) == ToPrimitive(B)</code></td>
</tr>
<tr>
<td></td>
<td>Object</td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>ToPrimitive(A) == B</code></td>
<td><code>ToPrimitive(A) == B</code></td>
<td><code>ToPrimitive(A) == ToNumber(B)</code></td>
<td><code>A === B</code></td>
</tr>
</tbody></table>
<h2 id="几个案例测试："><a href="#几个案例测试：" class="headerlink" title="几个案例测试："></a>几个案例测试：</h2><p>​        这个是我笔试的时候遇到的题目案例：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">console.log([] == ![])</span><br><span class="line">	对象和布尔之间的。第二个 ![] 属于 false</span><br><span class="line">	所以就是 [] 和 false 的比较，[] toString &#x27;&#x27;</span><br><span class="line">	然后字符串和布尔的比较，转number，都为 0</span><br><span class="line">	所以为 true</span><br><span class="line"></span><br><span class="line">console.log([&#x27;&#x27;] == false)</span><br><span class="line">	第二个一样：[&#x27;&#x27;] 的 toString 为 &#x27;&#x27;</span><br><span class="line">	所以也为true</span><br><span class="line">	</span><br><span class="line">console.log([] !== [])</span><br><span class="line">	对象的严格比较，直接比较地址的引用是否为同一个地址。</span><br><span class="line">	所以也为true</span><br><span class="line"></span><br><span class="line">console.log([&#x27;&#x27;] == [])</span><br><span class="line">	对象的比较，直接比较地址</span><br><span class="line">	false</span><br></pre></td></tr></table></figure>










      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/14/JavaScript/String%E6%96%B9%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/14/JavaScript/String%E6%96%B9%E6%B3%95/" class="post-title-link" itemprop="url">String方法</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-14 10:12:55" itemprop="dateCreated datePublished" datetime="2022-03-14T10:12:55+08:00">2022-03-14</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/%E9%9A%8F%E7%AC%94/" itemprop="url" rel="index"><span itemprop="name">随笔</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="String-的方法"><a href="#String-的方法" class="headerlink" title="String 的方法"></a>String 的方法</h1><h2 id="replace"><a href="#replace" class="headerlink" title="replace"></a>replace</h2><p>​        其实这个方法就是一个替换函数，并没有什么，但是我在一个公众号（Vue中文社区）里面发现，这样的替换的结果居然不是将其替换为’, ‘，而是中间插入，所以这个我想要知道为什么。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">let price = &#x27;123456789&#x27;</span><br><span class="line">let priceReg = /(?!^)(?=(\d&#123;3&#125;)+$)/g</span><br><span class="line"></span><br><span class="line">console.log(price.replace(priceReg, &#x27;,&#x27;)) //123,456,789</span><br></pre></td></tr></table></figure>

<p>​        先说结论：</p>
<p>​        所以简单来说，就是 ?= 这个方法可以形成这个效果。这个叫做正则表达式的先行断言和后行断言。</p>
<p>​        这里的这个 ?=p、?!p、?&lt;=p、?&lt;!p 这几个模式，我们可以在正则表达式里面进行学习，简单来说就是 ?=p，就是在p的前面为符合的条件，?!p，就是除了?=p 之外的所有。?&lt;=p，就是p的后面的条件。?&lt;!p，就是除了 ?&lt;=p 的所有。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">let priceReg = /(?=1)/g</span><br><span class="line"></span><br><span class="line">console.log(price.replace(priceReg, &#x27;,&#x27;)) //,123456789</span><br></pre></td></tr></table></figure>

<p>​        上面这个知道了。然后我们进行后续的学习 replace 方法。</p>
<h3 id="参数："><a href="#参数：" class="headerlink" title="参数："></a>参数：</h3><ul>
<li>字符串 或者 正则表达式</li>
<li>替换成新的字符串 或者 一个函数进行处理</li>
</ul>
<p>其中，对于新的字符串和函数作为参数，我们可以使用一些特殊变量名</p>
<h4 id="新的字符串作为参数："><a href="#新的字符串作为参数：" class="headerlink" title="新的字符串作为参数："></a>新的字符串作为参数：</h4><p>变量名    代表的值</p>
<ul>
<li>$$    插入一个 “$”。</li>
<li>$&amp;    插入匹配的子串。</li>
<li>$`    插入当前匹配的子串左边的内容。</li>
<li>$’    插入当前匹配的子串右边的内容。</li>
<li>$n    假如第一个参数是 RegExp对象，并且 n 是个小于100的非负整数，那么插入第 n 个括号匹配的字符串。提示：索引是从1开始。如果不存在第 n个分组，那么将会把匹配到到内容替换为字面量。比如不存在第3个分组，就会用“$3”替换匹配到的内容。</li>
<li>$<Name>     这里Name 是一个分组名称。如果在正则表达式中并不存在分组（或者没有匹配），这个变量将被处理为空字符串。只有在支持命名分组捕获的浏览器中才能使用。</Name></li>
</ul>
<p>这里我就简单说前面几个可能会常用的</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">let price = &#x27;123145617819&#x27;</span><br><span class="line">let priceReg = /1/g</span><br><span class="line">console.log(price.replace(priceReg, &#x27;$&amp;,&#x27;)) //1,231,4561,781,9</span><br></pre></td></tr></table></figure>

<p>​        上面有个案例，大概就能理解了。</p>
<ul>
<li><p>对于 $$ 不用思考，就像是 <code>\\</code> 一样，转义 <code>\</code> 的。</p>
</li>
<li><p>$&amp;，代表匹配上的字符串</p>
</li>
<li><p>$`，就是匹配字符串的左边的内容</p>
<ul>
<li>```<br>let price = ‘123145617819’<br>let priceReg = /\d{3}/gconsole.log(price.replace(priceReg, ‘$`,’)) // ,123,123145,123145617,<br>123 左侧没有，所以就只有一个 ,<br>145 左侧存在123，所以就是 123,<br>617 左侧为123145，所以就是 123145,<br>819 同上。<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">* $&#x27;，代表右边内容，意思同上。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#### 函数作为参数</span><br><span class="line"></span><br><span class="line">变量名	代表的值</span><br><span class="line"></span><br><span class="line">* match	匹配的子串。（对应于上述的$&amp;。）</span><br><span class="line">* p1,p2, ...	假如replace()方法的第一个参数是一个RegExp 对象，则代表第n个括号匹配的字符串。（对应于上述的$1，$2等。）例如，如果是用 /(\a+)(\b+)/ 这个来匹配，p1 就是匹配的 \a+，p2 就是匹配的 \b+。</span><br><span class="line">* offset	匹配到的子字符串在原字符串中的偏移量。（比如，如果原字符串是 &#x27;abcd&#x27;，匹配到的子字符串是 &#x27;bc&#x27;，那么这个参数将会是 1）</span><br><span class="line">* string	被匹配的原字符串。</span><br><span class="line">* NamedCaptureGroup	命名捕获组匹配的对象</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
console.log(price.replace(priceReg, () =&gt; {<br>console.log(‘1’)<br>}))</li>
</ul>
</li>
</ul>
<p>首先我们会发现，这个方法在每次匹配都会执行一次。</p>
<pre><code>
​        对于参数来说，因为参数的第二个是匹配的()，所以我们需要知道正则表达式的()的数量才能完成编写。

​        同时，返回值将替换原来的。

​        注意，此时的返回值将不能使用字符串参数里面的特殊变量了。
</code></pre>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/14/%E9%9A%8F%E7%AC%94/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/14/%E9%9A%8F%E7%AC%94/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" class="post-title-link" itemprop="url">正则表达式</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-14 10:12:12" itemprop="dateCreated datePublished" datetime="2022-03-14T10:12:12+08:00">2022-03-14</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/13/JavaScript/JavaScript%E8%8E%B7%E5%8F%96%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%9A%84%E8%BE%93%E5%85%A5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/13/JavaScript/JavaScript%E8%8E%B7%E5%8F%96%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%9A%84%E8%BE%93%E5%85%A5/" class="post-title-link" itemprop="url">JavaScript获取控制台的输入</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-13 20:51:51" itemprop="dateCreated datePublished" datetime="2022-03-13T20:51:51+08:00">2022-03-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/%E9%9A%8F%E7%AC%94/" itemprop="url" rel="index"><span itemprop="name">随笔</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="JavaScript如何获取控制台的输入"><a href="#JavaScript如何获取控制台的输入" class="headerlink" title="JavaScript如何获取控制台的输入"></a>JavaScript如何获取控制台的输入</h1><p>​        首先我们知道 JavaScript 是一个用于浏览器的一个脚本语言，但是因为 Node.js 的开发，JavaScript 也组件用于服务器开发。所以便有了从控制台获取输入的一个方法。</p>
<p>​        当然第一次需要从控制台里面获取输入还是在笔试的时候发现的，大部分的笔试题是一个ACM的形式，而leetcode是一个核心代码的形式。</p>
<p>​        所以在笔试里面就需要获取输入了。</p>
<h2 id="readline-模块"><a href="#readline-模块" class="headerlink" title="readline 模块"></a>readline 模块</h2><p>​        简单来说就是，我们使用 readline模块来提供一个可读流。</p>
<p>​        一个简单的案例：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">const rl = require(&#x27;readline&#x27;).createInterface(&#123;</span><br><span class="line">  input: process.stdin,</span><br><span class="line">  output: process.stdout</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">rl.on(&#x27;line&#x27;, (input) =&gt; &#123;</span><br><span class="line">  const index = input.lastIndexOf(&#x27;/&#x27;)</span><br><span class="line"></span><br><span class="line">  console.log(input.slice(index+1))</span><br><span class="line">  rl.close();</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>​        那么此时我们就可以获取到了控制台的输入了。</p>
<p>​        <code>readline.Interface</code> 类的实例是使用 <code>readline.createInterface()</code> 方法构造的。</p>
<p>​        这里 rl.on(‘line’)，代表的是interface的line事件。line事件就是在 \n、\r时会触发的事件，通常是用户按回车或者返回时。</p>
<p>​        当然还有其他事件，我们这里就取常用的 line事件，同时在加上一个close方法。调用这个方法将会停止可读流</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rl.close()，</span><br></pre></td></tr></table></figure>

<p>​        对于其他的方式我们就查看文档即可。这里不做过多的解释。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://nodejs.cn/api/readline.html</span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/12/%E6%B5%8F%E8%A7%88%E5%99%A8/SEO%E5%8E%9F%E7%90%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/12/%E6%B5%8F%E8%A7%88%E5%99%A8/SEO%E5%8E%9F%E7%90%86/" class="post-title-link" itemprop="url">SEO原理</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-12 13:11:02" itemprop="dateCreated datePublished" datetime="2022-03-12T13:11:02+08:00">2022-03-12</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E9%9A%8F%E7%AC%94/" itemprop="url" rel="index"><span itemprop="name">随笔</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="浏览器的-SEO-原理"><a href="#浏览器的-SEO-原理" class="headerlink" title="浏览器的 SEO 原理"></a>浏览器的 SEO 原理</h1><p>​        一次在公司的项目中，有幸使用了 nuxt + vue的一个开发流程。于是就有幸知道了服务端渲染和seo优化。</p>
<p>​        以前在学习的时候，就只是知道服务端渲染对于seo比较友好，并没有深刻的一个印象。</p>
<h2 id="服务端渲染"><a href="#服务端渲染" class="headerlink" title="服务端渲染"></a>服务端渲染</h2><p>​        我们这里就简单说一下是什么意思</p>
<p>​        因为 Vue 是一个 SPA 单页面应用。就是请求会将所有的页面内容返回回来，所以会导致第一次的请求会有白屏等待。</p>
<p>​        而服务端渲染，简单来说就是请求返回回来的是一个HTML页面，我们不需要一次将所有的页面都请求回来。这样既不会出现白屏等待，也有利于SEO优化。</p>
<p>​        那么什么是SEO优化呢。</p>
<h2 id="SEO优化"><a href="#SEO优化" class="headerlink" title="SEO优化"></a>SEO优化</h2><p>​        SEO 叫做 Search Engine Optimization，搜索引擎优化。</p>
<h3 id="原理"><a href="#原理" class="headerlink" title="原理"></a>原理</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://www.jianshu.com/p/77d32ca7cb9d</span><br></pre></td></tr></table></figure>

<p>​        就是搜索引擎会先在各个网站进行爬虫和信息收集。然后针对信息进行一个排名。</p>
<p>​        主要几个部分：</p>
<ul>
<li>关键字</li>
<li>外链，到各个网站上宣传，提高权重</li>
<li>robot文件：爬虫优化</li>
<li>内容的重心</li>
<li>css，标题，h标签，js操作。</li>
</ul>
<p>详细还是看上面那个简书的文章。</p>
<h3 id="服务端对于-seo-优化"><a href="#服务端对于-seo-优化" class="headerlink" title="服务端对于 seo 优化"></a>服务端对于 seo 优化</h3><p>​        所以服务端为什么有利于seo的优化。</p>
<p>​        因为服务端渲染可以让dom结构和内容被爬虫所读取</p>
<p>​        而原生的vue是一个动态的页面，所以爬虫将无法正常的读取内容，所以会不利于seo。</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2022/03/08/JavaScript/%E9%9A%8F%E7%AC%94/JavaScript%E6%A8%A1%E5%9D%97%E5%8C%96/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/03/08/JavaScript/%E9%9A%8F%E7%AC%94/JavaScript%E6%A8%A1%E5%9D%97%E5%8C%96/" class="post-title-link" itemprop="url">JavaScript模块化</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-03-08 22:21:48" itemprop="dateCreated datePublished" datetime="2022-03-08T22:21:48+08:00">2022-03-08</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/JavaScript/%E9%9A%8F%E7%AC%94/" itemprop="url" rel="index"><span itemprop="name">随笔</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="JavaScript-模块化"><a href="#JavaScript-模块化" class="headerlink" title="JavaScript 模块化"></a>JavaScript 模块化</h1><p>​        我们可以知道，JavaScript原来是应用于浏览器端的，所以当时是没有模块化的概念的。</p>
<p>​        在模块化之前，JavaScript主要使用闭包和立即执行函数来将方法用命名空间来进行划分。</p>
<p>​        但是后来Nodejs的诞生，将JavaScript带入了服务端之后，模块化就变得不可或缺。此时CommonJS便由此而生了。</p>
<p>模块化：</p>
<ul>
<li>后端：CommonJS 对应的 Node.js</li>
<li>前端：AMD 对应的 RequireJS  和 CMD 对应的 Sea.js</li>
<li>ES6：ES6 的模块化规范。</li>
</ul>
<h2 id="Nodejs-的-CommonJS"><a href="#Nodejs-的-CommonJS" class="headerlink" title="Nodejs 的 CommonJS"></a>Nodejs 的 CommonJS</h2><p>​    Nodejs 参照了 CommonJS 的规范，通过 require 和 exports 进行模块化。</p>
<p>​        关键词：require、exports、module.exports</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">简单的使用</span><br><span class="line">const depend = require(&#x27;../xxx&#x27;)</span><br><span class="line"></span><br><span class="line">module.exports.run = 1;</span><br><span class="line"></span><br><span class="line">这里：我们省略了后缀，node将按照一下顺序进行查找。其中，如果x是包模块，那么会查找 package.json 的main属性</span><br><span class="line">X.js</span><br><span class="line">X.json</span><br><span class="line">X.node</span><br><span class="line">X/index.js</span><br><span class="line">X/index.json</span><br><span class="line">X/index.node</span><br></pre></td></tr></table></figure>

<p>​    require 就是导入。</p>
<p>​    exports 就是导出的接口，是 module.exports 的一个引用，但是我们最终使用的时候还是使用的 module.exports。</p>
<p>​    所以，如果我们对 exports 的修改是一个对象的赋值，那么会导致exports会指向另外一个栈的地址，但是并不会修改到 model.exports。</p>
<p>​    所以如果我们要导出一个对象，那么我们就需要使用 module.exports，这样的修改才能造成影响。</p>
<p>​    CommonJS 的模块化，导出和缓存的步骤。</p>
<p><img src="/.io//nodejs-require.jpg" alt="nodejs-require"></p>
<p>​        我们会先判断引入的文件是否存在缓存区，同时判断是否是原生的模块，对于原生模块，回去判断是否在原生模块的缓存。然后最终就是加载和引入。</p>
<h2 id="AMD、CMD"><a href="#AMD、CMD" class="headerlink" title="AMD、CMD"></a>AMD、CMD</h2><p>AMD规范：RequireJS</p>
<p>​    AMD规范是异步的，通过define方法将代码定义为模块，在被require时加载依赖的模块。</p>
<p>​    AMD 是 “Asynchronous Module Definition” 的缩写，意思就是”异步模块定义”。</p>
<p>CMD规范：Sea.js</p>
<p>​        AMD和CMD的规范其实都差不多。只是AMD的一个异步的CMD是一个在书写上依照了CommonJS的一个规范。</p>
<h2 id="ES6"><a href="#ES6" class="headerlink" title="ES6"></a>ES6</h2><p>​        ES6模块化，Es6在后续也出现了模块化，就是</p>
<p>import，exports</p>
<ul>
<li>和commonjs的区别：</li>
</ul>
<p>​        CommonJS 只能在运行时确定导出的接口，实际导出的就是一个对象。而 ES6 Module 的设计思想是尽量的静态化，使得编译时就能确定模块的依赖关系，以及导入和导出的变量，也就是所谓的”编译时加载”。</p>
<p>​        正因为如此，<code>import</code> 命令具有提升效果，会提升到整个模块的头部，首先执行。</p>
<p>​        简单来说就是，我虽然没有先import，但是我还是会提前import。就像是function写在下面也可以调用一样。</p>
<p>​        也正因为 ES6 Module 是编译时加载， 所以不能使用表达式和变量，因为这些是只有在运行时才能得到结果的语法结构。</p>
<p>​        就是，不存在变量的使用情况，因为此时还没有。</p>
<p>​        commonjs 是深拷贝，而es6是浅拷贝</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/11/">11</a><a class="extend next" rel="next" href="/page/3/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>

</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">tallgy</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
